Skip to content

[ALLOC] Replace malloc_hack with guest-owned allocator model - #4728

Merged
ptitSeb merged 2 commits into
ptitSeb:mainfrom
ksco:allocator-ownership
Nov 16, 2026
Merged

ptitSeb merged 2 commits into
ptitSeb:mainfrom
ksco:allocator-ownership

Conversation

@ksco

@ksco ksco commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Keeps guest and host memory ownership separate instead of rewriting guest allocator entry points.
The new model detects when an emulated program globally replaces malloc/free, leaves that allocator untouched, and routes guest-visible wrapper allocations through the guest's allocator while box64 and native wrapped libraries stay on the host heap. free/realloc/usable-size calls dispatch by pointer provenance, using guest mmap ranges plus an isolated guest brk arena for classification.

BOX64_MALLOC_HACK and BOX64_LIBCEF env vars are removed.

Tested:

  • Node.js with npm
  • Bun (and Claude code)
  • Chromium (and Feishu)
  • Electron (and Heroic)
  • WeChat

All working fine.

Keeps guest and host memory ownership separate instead of rewriting guest allocator entry points.
The new model detects when an emulated program globally replaces malloc/free, leaves that allocator untouched, and routes guest-visible wrapper allocations through the guest's allocator while box64 and native wrapped libraries stay on the host heap. `free/realloc/usable-size` calls dispatch by pointer provenance, using guest mmap ranges plus an isolated guest brk arena for classification.

`BOX64_MALLOC_HACK` and `BOX64_LIBCEF` env vars are removed.

Tested:
- Node.js with npm
- Bun (and Claude code)
- Chromium
- Electron (and Heroic)
- WeChat

All working fine.
@ptitSeb

ptitSeb commented Nov 16, 2026

Copy link
Copy Markdown
Owner

The I is red. The new test seems to be failling.

@ksco

ksco commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator Author

Yeah, because static-build does not benefit from this.

@ptitSeb

ptitSeb commented Nov 16, 2026

Copy link
Copy Markdown
Owner

The idea seems very similar to former malloc_hook, but without the hooking itself, just letting the guest allocator do it's things. Did you try some box32 complex apps/games, and some AppImage (as brk been changed, staticaly linked stuffs might have been impacted).

I'm still woried that some direct jump to guest free can be done directly with a native pointer in it.

@ksco

ksco commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator Author

I tried several AppImages, and they worked well. Box32 should be unaffected, this is 64-bit only.

@ptitSeb
ptitSeb merged commit 96c2666 into ptitSeb:main Nov 16, 2026
29 checks passed
@ksco

ksco commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator Author

The idea seems very similar to former malloc_hook, but without the hooking itself, just letting the guest allocator do it's things.

Well, yeah, but there is an auto-detection now, so no manual BOX64_DYNAREC_MALLOC_HACK is needed.

@ksco
ksco deleted the allocator-ownership branch November 16, 2026 09:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants